//
//  BillDetailViewController.m
//  DistributorAB
//
//  Created by 主事丫环 on 2019/7/8.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "BillDetailViewController.h"
#import "CapitalPoolDynamicsVC.h"

@interface BillDetailViewController ()

@property (weak, nonatomic) IBOutlet UILabel *typeL;
@property (weak, nonatomic) IBOutlet UILabel *amountL;
@property (weak, nonatomic) IBOutlet UILabel *leftL1;
@property (weak, nonatomic) IBOutlet UILabel *leftL2;
@property (weak, nonatomic) IBOutlet UILabel *leftL3;
@property (weak, nonatomic) IBOutlet UILabel *leftL4;
@property (weak, nonatomic) IBOutlet UILabel *leftL5;
@property (weak, nonatomic) IBOutlet UILabel *leftL6;
@property (weak, nonatomic) IBOutlet UILabel *leftL7;
@property (weak, nonatomic) IBOutlet UILabel *rightL1;
@property (weak, nonatomic) IBOutlet UILabel *rightL2;
@property (weak, nonatomic) IBOutlet UILabel *rightL3;
@property (weak, nonatomic) IBOutlet UILabel *rightL4;
@property (weak, nonatomic) IBOutlet UILabel *rightL5;
@property (weak, nonatomic) IBOutlet UILabel *rightL6;
@property (weak, nonatomic) IBOutlet UILabel *rightL7;

@property (weak, nonatomic) IBOutlet UILabel *tipsL;
@property (weak, nonatomic) IBOutlet UIImageView *arrowIV;


@property (weak, nonatomic) IBOutlet UIButton *poolDynamicsB;

@end

@implementation BillDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"结算详情";
    [self.leftbutton setImage:imgname(@"left_icon") forState:(UIControlStateNormal)];
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    
    if ([self.from isEqualToString:@"1"]) {

        if ( [self.model.type integerValue] == 1) {
            _typeL.text = [NSString stringWithFormat:@"结算-微信"];
        }else if ( [self.model.type integerValue] == 2){
            _typeL.text = [NSString stringWithFormat:@"结算-支付宝"];
        }

        float floatStr = [self.model.app_count_money floatValue];
        NSString *returtStr = [NSString stringWithFormat:@"%.2f",floatStr];

        _amountL.text = returtStr;

        if ([self.model.state integerValue] == 0) {
            _rightL1.text = @"审核中";
            float floatStr1 = [self.model.app_count_money floatValue];
            float floatStr2 = [self.model.sxf floatValue];
            float floatStr3 = [self.model.actualMoney floatValue];
            
            NSString *returtStr1 = [NSString stringWithFormat:@"%.2f",floatStr1];
            NSString *returtStr2 = [NSString stringWithFormat:@"%.2f",floatStr2];
            NSString *returtStr3 = [NSString stringWithFormat:@"%.2f",floatStr3];

            _rightL2.text = [NSString stringWithFormat:@"¥%@", returtStr1];
            _rightL3.text = [NSString stringWithFormat:@"¥%@", returtStr2];
            _rightL4.text = [NSString stringWithFormat:@"¥%@", returtStr3];

            _rightL5.text = self.model.app_time;
            _leftL6.text = @"流水号";
            _rightL6.text = self.model.id;
            _leftL7.hidden = YES;
            _rightL7.hidden = YES;

        }else if ([self.model.state integerValue] == 1) {
            _rightL1.text = @"已到账";
            float floatStr1 = [self.model.app_count_money floatValue];
            float floatStr2 = [self.model.sxf floatValue];
            float floatStr3 = [self.model.actualMoney floatValue];
            
            NSString *returtStr1 = [NSString stringWithFormat:@"%.2f",floatStr1];
            NSString *returtStr2 = [NSString stringWithFormat:@"%.2f",floatStr2];
            NSString *returtStr3 = [NSString stringWithFormat:@"%.2f",floatStr3];
            
            _rightL2.text = [NSString stringWithFormat:@"¥%@", returtStr1];
            _rightL3.text = [NSString stringWithFormat:@"¥%@", returtStr2];
            _rightL4.text = [NSString stringWithFormat:@"¥%@", returtStr3];

            _rightL5.text = self.model.app_time;
            _rightL6.text = self.model.pay_time;
            _rightL7.text = self.model.id;
        }

        self.poolDynamicsB.hidden = YES;
        self.tipsL.hidden = YES;
        self.arrowIV.hidden = YES;

    }else {
    
        [self request];
        
        self.poolDynamicsB.hidden = NO;
        self.tipsL.hidden = NO;
        self.arrowIV.hidden = NO;

    }

    
}


- (void)request {
    
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithCapacity:1];
    param[@"id"] = self.bacModel.id;
    
    [NetWorkTool POST:@"/cs_user/agentSeetInfo" param:param success:^(id dic) {
        
        NSDictionary *dict = dic[@"data"];
        KMyLog(@"--------------------- %@",dic[@"data"]);
        
        if ( [dict[@"type"] integerValue] == 1) {
            self.typeL.text = [NSString stringWithFormat:@"结算-微信"];
        }else if ( [dict[@"type"] integerValue] == 2){
            self.typeL.text = [NSString stringWithFormat:@"结算-支付宝"];
        }

        self.amountL.text = dict[@"set_money"];

        if ([dict[@"set_state"] integerValue] == 0) {
            self.rightL1.text = @"审核中";
            self.rightL2.text = [NSString stringWithFormat:@"¥%@", dict[@"set_money"]];
            self.leftL3.text = @"资金池扣除";
            self.rightL3.text = [NSString stringWithFormat:@"¥%@", dict[@"capital_pool_money"]];
            self.rightL4.text = [NSString stringWithFormat:@"¥%@", dict[@"actual_money"]];

            self.leftL5.text = @"流水号";
            self.rightL5.text = dict[@"id"];
            self.leftL6.hidden = YES;
            self.rightL6.hidden = YES;
            self.leftL7.hidden = YES;
            self.rightL7.hidden = YES;

        }else if ([dict[@"set_state"] integerValue] == 1) {
            self.rightL1.text = @"已到账";
            self.rightL2.text = [NSString stringWithFormat:@"¥%@", dict[@"set_money"]];

            self.leftL3.text = @"资金池扣除";
            self.rightL3.text = [NSString stringWithFormat:@"¥%@", dict[@"capital_pool_money"]];
            self.rightL4.text = [NSString stringWithFormat:@"¥%@", dict[@"actual_money"]];
            self.leftL5.text = @"到账时间";
            self.rightL5.text = dict[@"pay_time"];
            self.leftL6.text = @"流水号";
            self.rightL6.text = dict[@"id"];
            self.leftL7.hidden = YES;
            self.rightL7.hidden = YES;
        }

    } other:^(id dic) {
        ShowToastWithText(dic[@"msg"]);
    } fail:^(NSError *error) {

    } needUser:YES];
    
    
}


- (IBAction)checkDynamic:(id)sender {
    
    CapitalPoolDynamicsVC *VC = [CapitalPoolDynamicsVC new];
    [self.navigationController pushViewController:VC animated:YES];
    
}

@end
